Skip to content

Try olvlvl/composer-attribute-collector #4064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 16, 2025

No description provided.

@ondrejmirtes
Copy link
Member

Won't work on PHP 7.4. But the idea is to rebase my fork on top of it and only have minimal changes there.

@staabm
Copy link
Contributor Author

staabm commented Jun 16, 2025

yeah, the problem is that it currently doesn't even work on PHP 8.x

@olvlvl
Copy link

olvlvl commented Jun 16, 2025

I cloned phpstan-src:2.1.x on my machine, but composer install hangs on this step:

  - Applying patches for composer/ca-bundle
    patches/cloudflare-ca.patch (0)

I removed all the "patches" and used my package. After the autoload dump I see the attribute file with collected target parameters. I guess the collector is doing its job.

    targetParameters: array (
  'PHPStan\\DependencyInjection\\AutowiredParameter' => 
  array (
    0 => 
    array (
      0 => 
      array (
        'ref' => '%currentWorkingDirectory%',
      ),
      1 => 'PHPStan\\File\\ParentDirectoryRelativePathHelper',
      2 => '__construct',
      3 => 'parentDirectory',
    ),
    1 => 
    array (
      0 => 
      array (
        'ref' => '%currentWorkingDirectory%',
      ),
      1 => 'PHPStan\\File\\FileHelper',
      2 => '__construct',
      3 => 'workingDirectory',
    ),

Running make tests I get the following error:

  Service of type PHPStan\Reflection\SignatureMap\NativeFunctionReflectionProvider: Service of type PHPStan\Reflection\SignatureMap\SignatureMapProvider re
  quired by $signatureMapProvider in NativeFunctionReflectionProvider::__construct() not found. Did you add it to configuration file?

I see SignatureMapProvider is an interface, not a class. The collector filters out interfaces.

After removing the interface filter I see the class in the dump:

    225 => 
    array (
      0 => 
      array (
        'factory' => '@PHPStan\\Reflection\\SignatureMap\\SignatureMapProviderFactory::create',
      ),
      1 => 'PHPStan\\Reflection\\SignatureMap\\SignatureMapProvider',
    ),

which matches the definition:

#[AutowiredService(factory: '@PHPStan\Reflection\SignatureMap\SignatureMapProviderFactory::create')]
interface SignatureMapProvider

After that, I get tons of these errors, but I guess that's because I'm running PHP 8.4.

Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /Volumes/git/phpstan-src/vendor/nette/di/src/DI/DependencyChecker.php on line 150
PHP Deprecated:  Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /Volumes/git/phpstan-src/vendor/nette/di/src/DI/DependencyChecker.php on line 150

Can you try on your side if removing the interface filter works? I don't mind collecting attributes on interfaces, it's just I never thought of this usage. In Plugin.php:

    private static function buildFileFilter(): Filter
    {
        return new Filter\Chain([
            new ContentFilter(),
            //new InterfaceFilter()
        ]);
    }

I created a Dockerfile with PHP 8.2, restored the "patches", and ran composer up. All patches were applied except this one:

  - Applying patches for react/http
    patches/Sender.patch (0)
   Could not apply patch! Skipping. The error was: Cannot apply patch patches/Sender.patch

Then, running make test gave me the following error:

In Processor.php line 94:
                                           
  Unexpected item 'parameters › baseUrl'.  
                                           

It would be great to have a Dockerfile for reproducible runs.

@ondrejmirtes
Copy link
Member

@olvlvl If you're on macOS the fix for patches is described in the README.

Other than that the project works without issues even on PHP 8.4.

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

I started from zero inside a PHP 8.2 container. I swapped your package with mine and disabled the interface filter. Now the tests are passing:

image

But PHPStan finds some shenanigans because I renamed MethodParameter as Parameter. Should be easily fixed:

image

I'm gonna disable the interface filter and merge that into main, then rebase my branch. And hopefully, it should work :)

@ondrejmirtes
Copy link
Member

Yeah, that's one of the commits I did ondrejmirtes/composer-attribute-collector@d285f54

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

The PR is ready over here: olvlvl/composer-attribute-collector#38

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

The changes are ready: olvlvl/composer-attribute-collector#37. I've tested phpstan-src, the tests are passing. Let me know how it goes for you 🤞

@staabm
Copy link
Contributor Author

staabm commented Jun 17, 2025

I think it looks great, thank you.

PHP7.4 failling is expected as this is only supported on ondrejs fork.
but since PHP8.x jobs are green it seems it works

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

Great! I'm gonna merge the changes to main. I have other PRs that I want to include in 2.1. I'll make a new release soon after. Thanks for your contribution.

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

Gentlemen, please use the development branch 2.1. I like to keep main in sync with the latest release to avoid confusing users checking the README.

@olvlvl
Copy link

olvlvl commented Jun 17, 2025

I released v2.1.0 and killed the 2.1 dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants